//
//  ReportCardProblemTCell.m
//  jzyParents
//
//  Created by 任辰东 on 2022/8/22.
//

#import "ReportCardProblemTCell.h"

@interface ReportCardProblemTCell ()
@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) UILabel *label1;
@property (nonatomic, strong) UILabel *label2;
@property (nonatomic, strong) UILabel *label3;
@property (nonatomic, strong) UILabel *label4;
@property (nonatomic, strong) UILabel *label5;
@property (nonatomic, strong) UIImageView *arrow;
@property (nonatomic, strong) UILabel *detailLabel;
@end

@implementation ReportCardProblemTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)configCellWithModel:(Xiaoti_score_tongjiItem *)model
{
    self.label1.text = model.ti_name_show;
//    //1.单选;2.多选;3.填空;4.解答
//    if (model.ti_type.integerValue == 1) {
//        self.label2.text = @"单选题";
//        self.label3.text = model.daan_true;
//    }else if (model.ti_type.integerValue == 2){
//        self.label2.text = @"多选题";
//        self.label3.text = model.daan_true;
//    }else if (model.ti_type.integerValue == 3){
//        self.label2.text = @"填空题";
//        self.label3.text = @"-";
//    }else{
//        self.label2.text = @"解答题";
//        self.label3.text = @"-";
//    }
    self.label2.text = model.ti_type;
    self.label3.text = model.ti_ke_answer;
    self.label4.text = [NSString stringWithFormat:@"%@/%@",IsEmpty(model.defen)?@"":model.defen,IsEmpty(model.manfen)?@"":model.manfen];
    self.label5.text = @"均分";
    self.detailLabel.hidden = !model.isOpen;
    CGFloat width = (kScreenWidth - 15 *2) /5.0;
    if (model.isOpen) {
        self.arrow.image = UIImageWithName(@"arrow_up");
        self.label5.text = @"收起";
        self.detailLabel.text = model.junfen;
        [self.label5 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.label4.mas_right).offset(-2-9.5);
            make.top.equalTo(self.containerView).offset(7);
            make.width.mas_equalTo(width);
        }];

        [self.detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {

            make.left.equalTo(self.containerView).offset(15);
            make.right.equalTo(self.containerView).offset(-15);
            make.top.equalTo(self.label1.mas_bottom).offset(15);
            make.bottom.equalTo(self.containerView).offset(-7);
        }];
    }else{
        self.arrow.image = UIImageWithName(@"arrow_down");
        self.detailLabel.text = @"";
        self.label5.text = @"均分";
        [self.label5 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.label4.mas_right).offset(-2-9.5);
            make.top.equalTo(self.containerView).offset(7);
            make.width.mas_equalTo(width);
            make.bottom.equalTo(self.containerView).offset(-7);
        }];

        [self.detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.containerView).offset(15);
            make.right.equalTo(self.containerView).offset(-15);
            make.top.equalTo(self.containerView).offset(15);
            make.height.mas_equalTo(0);
        }];
    }
    [self.contentView layoutIfNeeded];
    
}

-(void)setupViews
{
    [self.contentView addSubview:self.containerView];
    [self.containerView addSubview:self.label1];
    [self.containerView addSubview:self.label2];
    [self.containerView addSubview:self.label3];
    [self.containerView addSubview:self.label4];
    [self.containerView addSubview:self.label5];
    [self.containerView addSubview:self.arrow];
    [self.containerView addSubview:self.detailLabel];
}

-(void)setupLayout
{
    [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self.contentView);
    }];
    
    CGFloat width = (kScreenWidth - 15 *2) /5.0;
    [self.label1 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.containerView).offset(15);
        make.top.equalTo(self.containerView).offset(7);
        make.width.mas_equalTo(width);
    }];
    
    [self.label2 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.label1.mas_right).offset(0);
        make.top.equalTo(self.containerView).offset(7);
        make.width.mas_equalTo(width);
    }];
    
    [self.label3 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.label2.mas_right).offset(0);
        make.top.equalTo(self.containerView).offset(7);
        make.width.mas_equalTo(width);
    }];
    
    [self.label4 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.label3.mas_right).offset(0);
        make.top.equalTo(self.containerView).offset(7);
        make.width.mas_equalTo(width);
    }];
    
    [self.label5 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.label4.mas_right).offset(-2-9.5);
        make.top.equalTo(self.containerView).offset(7);
        make.width.mas_equalTo(width - 2 - 9.5);
    }];

    
    [self.arrow mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.label5.mas_right).offset(2);
        make.centerY.equalTo(self.label5);
        make.width.mas_equalTo(9.5);
        make.height.mas_equalTo(6);
    }];
    
    [self.detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.left.equalTo(self.containerView).offset(15);
        make.right.equalTo(self.containerView).offset(-15);
        make.top.equalTo(self.label1.mas_bottom).offset(15);
        make.bottom.equalTo(self.containerView).offset(-7);
    }];
}

#pragma mark -- lazyload

-(UIView *)containerView
{
    if (!_containerView) {
        _containerView = [UIView new];
        _containerView.backgroundColor = UIColorFromHex(kColorWhite);
    }
    return _containerView;
}

-(UILabel *)label1
{
    if (!_label1) {
        _label1 = [UILabel new];
        _label1.textColor = UIColorFromHex(0x000000);
        _label1.font = UIFontSize(13);
        _label1.textAlignment = NSTextAlignmentLeft;
    }
    return _label1;
}

-(UILabel *)label2
{
    if (!_label2) {
        _label2 = [UILabel new];
        _label2.textColor = UIColorFromHex(0x000000);
        _label2.font = UIFontSize(13);
        _label2.textAlignment = NSTextAlignmentCenter;
    }
    return _label2;
}

-(UILabel *)label3
{
    if (!_label3) {
        _label3 = [UILabel new];
        _label3.textColor = UIColorFromHex(0x000000);
        _label3.font = UIFontSize(13);
        _label3.textAlignment = NSTextAlignmentCenter;
    }
    return _label3;
}


-(UILabel *)label4
{
    if (!_label4) {
        _label4 = [UILabel new];
        _label4.textColor = UIColorFromHex(0x000000);
        _label4.font = UIFontSize(13);
        _label4.textAlignment = NSTextAlignmentCenter;
    }
    return _label4;
}

-(UILabel *)label5
{
    if (!_label5) {
        _label5 = [UILabel new];
        _label5.textColor = UIColorFromHex(0x666666);
        _label5.font = UIFontSize(13);
        _label5.textAlignment = NSTextAlignmentRight;
    }
    return _label5;
}

-(UILabel *)detailLabel
{
    if (!_detailLabel) {
        _detailLabel = [UILabel new];
        _detailLabel.textColor = UIColorFromHex(0x999999);
        _detailLabel.font = UIFontSize(12);
    }
    return _detailLabel;
}

-(UIImageView *)arrow
{
    if (!_arrow) {
        _arrow = [[UIImageView alloc]initWithImage:UIImageWithName(@"arrow_down")];
    }
    return _arrow;
}

@end
